package com.xyzh05.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="pricing")
@Searchable
@XmlRootElement
public class Pricing extends BaseObject implements Serializable {
	private static final long serialVersionUID = 3132266329575254068L;
	
	private Long id;
    private User user;
    private Service service;
    private Double price;

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
   
	@OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="userid", nullable=false)
    public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="serviceid", nullable=false)
    public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	@Column(name="price", nullable=false, precision=22, scale=0)
    @SearchableProperty
    public Double getPrice() {
        return this.price;
    }
    
    public void setPrice(Double price) {
        this.price = price;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Pricing pojo = (Pricing) o;

        if (user != null ? !user.equals(pojo.user) : pojo.user != null) return false;
        if (service != null ? !service.equals(pojo.service) : pojo.service != null) return false;
        if (price != null ? !price.equals(pojo.price) : pojo.price != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (user != null ? user.hashCode() : 0);
        result = 31 * result + (service != null ? service.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("user").append("='").append(getUser()).append("', ");
        sb.append("service").append("='").append(getService()).append("', ");
        sb.append("price").append("='").append(getPrice()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
